package fair.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import fair.dao.MemberDao;
import fair.pojo.Member;
import fair.service.MemberService;
import fair.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author fair_wu
 * @version v1.0
 * @package fair.service.impl
 * @date 2021-01-29 下午 22:26
 */

@Transactional
@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao dao;

    @Override
    public Member findByTelephone(String telephone) {
        return dao.findByTelephone(telephone);
    }

    @Override
    public void addMember(Member member) {
        String password = member.getPassword();
        if (password != null){
            //使用md5将明文密码加密
            member.setPassword(MD5Utils.md5(password));
        }
        dao.add(member);
    }

    @Override
    public List<Integer> findMemberCountByMouth(List<String> mouths) {
        List<Integer> counts = new ArrayList<>();
        for (String mouth : mouths) {
          String date = mouth + ".31";
          Integer count = dao.findCountByMouth(date);
          counts.add(count);
        }
        return counts;
    }
}
